package com.mantru.iotpot.job;

import com.mantru.iotpot.modbus.Common;
import com.mantru.iotpot.ApplicationClass;
import org.json.JSONObject;

/**
 * 炒菜步骤
 */
public class CookingSteep {
    //序号，从1自增
    public int id;
    //步骤类型：1加热设置、2调味料投放、3料盒投放、4手动投放
    public int steep_type;
    //步骤序号，从1开始
    public int steep_index;
    //步骤名称
    public String steep_name;
    //锅档位，0-9档，值越大表示火力越大
    public int fire_value;
    //开始时长的缩写格式，格式mm:ss
    public String time_value;
    //开始时长，将time_value转换为秒的值，单位：秒
    public int time_long;
    //机械爪转速，0-5档，steep_type=1时有效
    public int gripper_speed_value;
    //机械爪转向，0正方向、1反方向、2周期正反转，steep_type=1时有效
    public int gripper_rotation_value;
    //机械爪位置，1放下、2抬起，steep_type=1时有效
    public int gripper_position_value;

    //生抽，单位：克，这里是第1喷嘴，在t_public_config_newpot.device_param_001字段里配置了g、ml和秒的转换公式，steep_type=2时有效
    public int nozzle1_value;
    //老抽，单位：克，这里是第2喷嘴，在t_public_config_newpot.device_param_002字段里配置了g、ml和秒的转换公式，steep_type=2时有效
    public int nozzle2_value;
    //蚝油，单位：克，这里是第3喷嘴，在t_public_config_newpot.device_param_003字段里配置了g、ml和秒的转换公式，steep_type=2时有效
    public int nozzle3_value;
    //动物油A，单位：克，这里是第4喷嘴，在t_public_config_newpot.device_param_004字段里配置了g、ml和秒的转换公式，steep_type=2时有效
    public int nozzle4_value;
    //动物油B，单位：克，这里是第5喷嘴，在t_public_config_newpot.device_param_005字段里配置了g、ml和秒的转换公式，steep_type=2时有效
    public int nozzle5_value;
    //植物油，单位：克，这里是第6喷嘴，在t_public_config_newpot.device_param_006字段里配置了g、ml和秒的转换公式，steep_type=2时有效
    public int nozzle6_value;
    //盐水，单位：克，这里是第7喷嘴，在t_public_config_newpot.device_param_007字段里配置了g、ml和秒的转换公式，steep_type=2时有效
    public int nozzle7_value;
    //醋，单位：克，这里是第8喷嘴，在t_public_config_newpot.device_param_008字段里配置了g、ml和秒的转换公式，steep_type=2时有效
    public int nozzle8_value;
    //淀粉水，单位：克，这里是第9喷嘴，在t_public_config_newpot.device_param_009字段里配置了g、ml和秒的转换公式，steep_type=2时有效
    public int nozzle9_value;
    //烹饪水，单位：克，这里是第10喷嘴，在t_public_config_newpot.device_param_010字段里配置了g、ml和秒的转换公式，steep_type=2时有效
    public int nozzle10_value;
    //洗锅水，单位：克，这里是第11喷嘴，在t_public_config_newpot.device_param_011字段里配置了g、ml和秒的转换公式，steep_type=2时有效
    public int nozzle11_value;
    //料盒1里填放的品相名称，steep_type=3时有效
    public String box1_name;
    //料盒1里填放的品相重量，单位：克，steep_type=3时有效
    public int box1_value;
    //料盒2里填放的品相名称，steep_type=3时有效
    public String box2_name;
    //料盒2里填放的品相重量，单位：克，steep_type=3时有效
    public int box2_value;
    //料盒3里填放的品相名称，steep_type=3时有效
    public String box3_name;
    //料盒3里填放的品相重量，单位：克，steep_type=3时有效
    public int box3_value;
    //料盒4里填放的品相名称，steep_type=3时有效
    public String box4_name;
    //料盒4里填放的品相重量，单位：克，steep_type=3时有效
    public int box4_value;
    //投菜避让：1是、0否，steep_type=3时有效
    public int box_need_avoid;
    //投菜方式：1常规投菜（投两下）、2慢速投菜（滞留几秒后归位，不抖动）、3快速投菜（投三下）、4慢速投菜（投三下），steep_type=3时有效
    public int box_release_type;
    //自动语音播报文本
    public String tts_text;
    //开始执行、结束执行、已执行的时间截，13位，单位：ms
    public long begin_time = 0, end_time = 0, pass_time = 0;
    //显示到步骤图上的数据
    public String steep_show_data;


    public CookingSteep(ApplicationClass ac, JSONObject obj, int index, int id){
        try {
            this.id = id;
            this.steep_type = obj.getInt("steep_type");
            this.steep_index = index;
            this.time_value = obj.getString("time_value");
            this.time_long = obj.getInt("time_long");
            this.steep_name = "";
            this.steep_show_data = "";

            if (this.steep_type == 1) {
                this.steep_name = "加热设置";
                this.fire_value = obj.getInt("fire_value");
                this.gripper_speed_value = obj.getInt("gripper_speed_value");
                this.gripper_rotation_value = obj.getInt("gripper_rotation_value");
                this.gripper_position_value = obj.getInt("gripper_position_value");
                //0正方向、1反方向、2周期正反转
                String data = "顺时针";
                if (this.gripper_position_value == 1) data = "逆时针";
                if (this.gripper_position_value == 2) data = "正反转";
                this.steep_show_data = ",\"火力："+this.fire_value+"\",\"档位："+this.gripper_speed_value+"\",\"转向："+data+"\"";
            }
            if (this.steep_type == 2) {
                this.steep_name = "调味料投放";
                if (obj.has("nozzle1_value")) this.nozzle1_value = obj.getInt("nozzle1_value");
                if (obj.has("nozzle2_value")) this.nozzle2_value = obj.getInt("nozzle2_value");
                if (obj.has("nozzle3_value")) this.nozzle3_value = obj.getInt("nozzle3_value");
                if (obj.has("nozzle4_value")) this.nozzle4_value = obj.getInt("nozzle4_value");
                if (obj.has("nozzle5_value")) this.nozzle5_value = obj.getInt("nozzle5_value");
                if (obj.has("nozzle6_value")) this.nozzle6_value = obj.getInt("nozzle6_value");
                if (obj.has("nozzle7_value")) this.nozzle7_value = obj.getInt("nozzle7_value");
                if (obj.has("nozzle8_value")) this.nozzle8_value = obj.getInt("nozzle8_value");
                if (obj.has("nozzle9_value")) this.nozzle9_value = obj.getInt("nozzle9_value");
                if (obj.has("nozzle10_value")) this.nozzle10_value = obj.getInt("nozzle10_value");
                if (obj.has("nozzle11_value")) this.nozzle11_value = obj.getInt("nozzle11_value");
                String nozzle_list = "";
                if (this.nozzle1_value > 0) { if (nozzle_list.length() > 0) nozzle_list += "、"; nozzle_list += Common.nozzle_name_list[1] + this.nozzle1_value + "g"; steep_show_data += ",\"" + Common.nozzle_name_list[1] + this.nozzle1_value + "g\"";}
                if (this.nozzle2_value > 0) { if (nozzle_list.length() > 0) nozzle_list += "、"; nozzle_list += Common.nozzle_name_list[2] + this.nozzle2_value + "g"; steep_show_data += ",\"" + Common.nozzle_name_list[2] + this.nozzle2_value + "g\"";}
                if (this.nozzle3_value > 0) { if (nozzle_list.length() > 0) nozzle_list += "、"; nozzle_list += Common.nozzle_name_list[3] + this.nozzle3_value + "g"; steep_show_data += ",\"" + Common.nozzle_name_list[3] + this.nozzle3_value + "g\"";}
                if (this.nozzle4_value > 0) { if (nozzle_list.length() > 0) nozzle_list += "、"; nozzle_list += Common.nozzle_name_list[4] + this.nozzle4_value + "g"; steep_show_data += ",\"" + Common.nozzle_name_list[4] + this.nozzle4_value + "g\"";}
                if (this.nozzle5_value > 0) { if (nozzle_list.length() > 0) nozzle_list += "、"; nozzle_list += Common.nozzle_name_list[5] + this.nozzle5_value + "g"; steep_show_data += ",\"" + Common.nozzle_name_list[5] + this.nozzle5_value + "g\"";}
                if (this.nozzle6_value > 0) { if (nozzle_list.length() > 0) nozzle_list += "、"; nozzle_list += Common.nozzle_name_list[6] + this.nozzle6_value + "g"; steep_show_data += ",\"" + Common.nozzle_name_list[6] + this.nozzle6_value + "g\"";}
                if (this.nozzle7_value > 0) { if (nozzle_list.length() > 0) nozzle_list += "、"; nozzle_list += Common.nozzle_name_list[7] + this.nozzle7_value + "g"; steep_show_data += ",\"" + Common.nozzle_name_list[7] + this.nozzle7_value + "g\"";}
                if (this.nozzle8_value > 0) { if (nozzle_list.length() > 0) nozzle_list += "、"; nozzle_list += Common.nozzle_name_list[8] + this.nozzle8_value + "g"; steep_show_data += ",\"" + Common.nozzle_name_list[8] + this.nozzle8_value + "g\"";}
                if (this.nozzle9_value > 0) { if (nozzle_list.length() > 0) nozzle_list += "、"; nozzle_list += Common.nozzle_name_list[9] + this.nozzle9_value + "g"; steep_show_data += ",\"" + Common.nozzle_name_list[9] + this.nozzle9_value + "g\"";}
                if (this.nozzle10_value > 0) { if (nozzle_list.length() > 0) nozzle_list += "、"; nozzle_list += Common.nozzle_name_list[10] + this.nozzle10_value + "g"; steep_show_data += ",\"" + Common.nozzle_name_list[10] + this.nozzle10_value + "g\"";}
                if (this.nozzle11_value > 0) { if (nozzle_list.length() > 0) nozzle_list += "、"; nozzle_list += Common.nozzle_name_list[11] + this.nozzle11_value + "g"; steep_show_data += ",\"" + Common.nozzle_name_list[11] + this.nozzle11_value + "g\"";}
                this.steep_name += "（" + nozzle_list + "）";
                ac.SaveLog("steep_name=" + this.steep_name);
                ac.SaveLog("obj=" + obj.toString());
            }
            if (this.steep_type == 3) {
                this.steep_name = "料盒投放";
                this.box1_name = obj.getString("box1_name");
                this.box1_value = obj.getInt("box1_value");
                this.box2_name = obj.getString("box2_name");
                this.box2_value = obj.getInt("box2_value");
                this.box3_name = obj.getString("box3_name");
                this.box3_value = obj.getInt("box3_value");
                this.box4_name = obj.getString("box4_name");
                this.box4_value = obj.getInt("box4_value");
                this.box_need_avoid = obj.getInt("box_need_avoid");
                this.box_release_type = obj.getInt("box_release_type");
                if (this.box1_name.length() > 0 && this.box1_value > 0) { this.steep_name = "料盒1投放（" + this.box1_name + this.box1_value + "g）"; steep_show_data = this.box1_name + "：" + this.box1_value + "g"; }
                if (this.box2_name.length() > 0 && this.box2_value > 0) { this.steep_name = "料盒2投放（" + this.box2_name + this.box2_value + "g）"; steep_show_data = this.box2_name + "：" + this.box2_value + "g"; }
                if (this.box3_name.length() > 0 && this.box3_value > 0) { this.steep_name = "料盒3投放（" + this.box3_name + this.box3_value + "g）"; steep_show_data = this.box3_name + "：" + this.box3_value + "g"; }
                if (this.box4_name.length() > 0 && this.box4_value > 0) { this.steep_name = "料盒4投放（" + this.box4_name + this.box4_value + "g）"; steep_show_data = this.box4_name + "：" + this.box4_value + "g"; }
                String[] data_list = new String[0];
                if (steep_show_data.contains("、"))
                    data_list = steep_show_data.split("、");
                else if (steep_show_data.contains("，"))
                    data_list = steep_show_data.split("，");
                else if (steep_show_data.contains(","))
                    data_list = steep_show_data.split(",");
                else if (steep_show_data.contains("；"))
                    data_list = steep_show_data.split("；");
                else if (steep_show_data.contains(";"))
                    data_list = steep_show_data.split(";");
                else if (steep_show_data.contains("|"))
                    data_list = steep_show_data.split("|");
                else
                    steep_show_data.split(" ");
                steep_show_data = "";
                for (int i=0; i<data_list.length; i++) {
                    String data2 = data_list[i].trim();
                    if (data2.length() > 0)
                        steep_show_data += ",\""+data2+"\"";
                }

            }
            if (this.steep_type == 4) {
                this.steep_name = "手动投放";
            }
            this.tts_text = "";
            if (obj.has("tts_text"))
                this.tts_text = obj.getString("tts_text");
        } catch (Exception ex) {
            ac.SaveLog("CookingSteep初始化出错：" + ex.getMessage());
        }

        begin_time = 0;
        end_time = 0;
        pass_time = 0;
    }

}
